% imOut=filterSeperable(H,im) - performs a 2-D filter using seperable filters
%This function will perform a 2D filter using two 1D filters.  Currently this 
%implementation will only zero pad before filters and does not all the boundries 
%to be symmetric.
%
%INPUT ARGUMENT
%H - a cell array of length 2 where the cells contain filter coefficients
%    H{1} will filter down the columns of im and H{2} will filter across
%    the rows of im.  This follows the format of the filter command
%im - image 
%
%OUTPUT ARGUMENT
%imOut - the filtered image
%
%Author: Paul Otto
function im=filterSeperable(H,im)

if ~(all(size(H)==[2 1]) || all(size(H)==[2 1]))
    error('H must be a cell of size 2')
    end
    
if mod(length(H{1}),2)==0
  warning('H{1}''s length is even and the image will be shifted.')   
end
  
if mod(length(H{2}),2)==0
  warning('H{2}''s length is even and the image will be shifted.')
end

%the zero padding will be even
zeropadding1=(length(H{1})-mod(length(H{1}),2));
zeropadding2=(length(H{2})-mod(length(H{2}),2));

%for the dimensions of the filter 1 goes down, 2 goes across
%we need to pad the top and bottom first
im_zeropad=zeros(size(im,1)+zeropadding1/2,size(im,2));
im_zeropad(1:size(im,1),:)=im;
im_zeropad=filter(H{1},1,im_zeropad,[],1);
im(:,:)=im_zeropad((zeropadding1/2+1):((zeropadding1/2)+size(im,1)),:);


im_zeropad=zeros(size(im,2),size(im,2)+zeropadding2/2);
im_zeropad(:,1:size(im,2))=im;
im_zeropad=filter(H{2},1,im_zeropad,[],2);


im(:,:)=im_zeropad(:,(zeropadding2/2+1):((zeropadding2/2)+size(im,2)));
